/*
* @Author: Administrator
* @Date:   2017-11-03 15:38:09
* @Last Modified by:   Administrator
* @Last Modified time: 2017-11-22 14:48:20
*/
 
 $(function(){

    $("footer").load("layout/footer.html");
    $("header").load("layout/header2.html");

 var listHtml=$('#list').html();
 var navHtml=$('#nav').html();
 var cityHtml=$('#city').html();

 $(function() {
              $.ajax({
                       type:"get",
                       url:"data/provience.json",
                       async:true,
                       success: function(data){
                        console.log(data.nav.length);
                        var navdata=data.nav
                        $('.navlis').html(doT.template(navHtml)(navdata));
                       },
                       error: function(XMLHTTPRequest, textStatus, errorThrown){
                         console.log("XMLHttpRequest :"+ XMLHTTPRequest);
                         console.log("textStatus :"+textStatus);
                         console.log("errorThrown :"+errorThrown);
                       }
                     });
             
       
    });
// 导航
$(document).on("click",".navlis button",function(){
  $(this).addClass("changered").siblings().removeClass("changered");
})
// 更多
$(document).on("click",".morecity",function(){
  if($(".list-nav li:nth-child(2)").height()==50){
      $(".list-nav li:nth-child(2)").height(160)
  }else{
    $(".list-nav li:nth-child(2)").height(50)
  }
})
// 排序
$(document).on("click",".sort-item",function(){
  $(this).addClass("changered").siblings().removeClass("changered");
})
// 布局方式
$(document).on("click",".sort-way",function(){
  $(this).addClass("changebg").siblings().removeClass("changebg");
  $(".p-list-con").hasClass("item")?$(".p-list-con").removeClass("item"):$(".p-list-con").addClass("item")
})
// 省份点击
$(document).on("click",".citybtn",function(){
  var _this=this
    $.ajax({
                type:"get",
                url:"data/provience.json",
                async:true,
                success: function(data){
                  var navdata=data.nav[1].case
                  console.log(navdata)
                  console.log(_this.value)
                  for(var i=0;i<navdata.length;i++){
                    if(_this.value==navdata[i].name){
                     $(".list-nav li:nth-child(3)").html(doT.template(cityHtml)(navdata[i].citys)); 
                    }
                  }
                },
                error: function(XMLHTTPRequest, textStatus, errorThrown){
                  console.log("XMLHttpRequest :"+ XMLHTTPRequest);
                  console.log("textStatus :"+textStatus);
                  console.log("errorThrown :"+errorThrown);
                }
         });
})

    //分页 
    function ajaxTest(num) {
      $.ajax({
        url: "data/table"+num+".json",
        type: "get",
        data: {},
        dataType: "json",
        success: function(data) {
          // console.log(data);
           var listdata=data.list;
           $('.p-list-con').html(doT.template(listHtml)(listdata));
           $("html,body").animate({
              "scrollTop" : 0
            },400);
          //分页
          $("#page").paging({
            pageNo: num,
            totalPage: data.totalPage,
            totalSize: data.totalSize,
            callback: function(num) {
              console.log(typeof data)
              ajaxTest(num)
            }
          })
        }
      })
    }

   ajaxTest(1);
})
